﻿using FT.Architecture.Utils.Log;

namespace FT.Architecture.Logging
{
    public class LogService : ILogService
    {
        private const string FtArchitectureUnitOfWorkLogger = "FT.Architecture.UnitOfWork";
        private const string FtArchitectureRepositoryLogger = "FT.Architecture.Repository";

        private readonly ILogger unitOfWorkLogger;
        private readonly ILogger repositoryLogger;

        public LogService(ILoggerFactory loggerFactory)
        {
            if (loggerFactory != null)
            {
                this.unitOfWorkLogger = loggerFactory.Build(FtArchitectureUnitOfWorkLogger);
                this.repositoryLogger = loggerFactory.Build(FtArchitectureRepositoryLogger);

                if (unitOfWorkLogger != null && repositoryLogger != null)
                    return;
            }

            if (unitOfWorkLogger == null)
                unitOfWorkLogger = new BlackholeLogger(FtArchitectureUnitOfWorkLogger);

            if (repositoryLogger == null)
                repositoryLogger = new BlackholeLogger(FtArchitectureRepositoryLogger);
        }

        public ILogger UnitOfWork
        {
            get
            {
                return unitOfWorkLogger;
            }
        }

        public ILogger Repository
        {
            get
            {
                return repositoryLogger;
            }
        }
    }
}
